﻿Imports System.Data
Imports System.Data.Odbc
Imports WSEntidades
Imports Utilerias
Imports MySql.Data.MySqlClient

Public Class CertificadosFact
    Public Shared Function Build(ByVal dr As MySqlDataReader, ByVal esParaListado As Boolean) As CertificadoBE
        Dim tmpCert As CertificadoBE = New CertificadoBE
        Try
            With tmpCert
                '.IdCertificado = convertDTFromDb.convertInt32(dr.Item("IdCertificado"))
                .NumeroCertificado = convertDTFromDb.ConvertString(dr.Item("NumCertif"))
                If (Not esParaListado) Then
                    .CertificadoPublico = convertDTFromDb.ConvertString(dr.Item("CertPublic"))
                    .CertificadoPrivado = convertDTFromDb.ConvertString(dr.Item("CertPriv"))
                    .ContraseñaPrivada = RijndaelSimple.desencriptaDefault(convertDTFromDb.ConvertString(dr.Item("ContrPriv")))
                    .Pfx = convertDTFromDb.GetByteArray(dr.Item("pfx"))
                End If
                Select Case convertDTFromDb.ConvertString(dr.Item("Tipo"))
                    Case "C"
                        .Tipo = CertificadoBE.tipoCertificado.CSD
                    Case "F"
                        .Tipo = CertificadoBE.tipoCertificado.FIEL
                End Select

                Select Case convertDTFromDb.ConvertString(dr.Item("Estado"))
                    Case "A"
                        .Estado = CertificadoBE.estadoCertificado.Activo
                    Case "I"
                        .Estado = CertificadoBE.estadoCertificado.Inactivo
                End Select
                .InicioVig = convertDTFromDb.convertDateTime(dr.Item("IniciaVig"))
                .FinVig = convertDTFromDb.convertDateTime(dr.Item("FinVig"))

                Select Case convertDTFromDb.ConvertString(dr.Item("DeCancelacion"))
                    Case "S"
                        .UsarEnCancelacion = True
                    Case "N"
                        .UsarEnCancelacion = False
                End Select

            End With

            Return tmpCert
        Catch ex As Exception
            Throw
        Finally
            tmpCert = Nothing
        End Try
    End Function
End Class
